<template>
  <el-dialog title="Activiti工作流在线流程设计器" :visible.sync="visible" :before-close="handleClose" fullscreen>
    <div class="modeler">
      <iframe class="iframe" :src="src" />
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    modelId: String
  },

  data() {
    return {
      visible: false
    }
  },

  computed: {
    src() {
      const src = '/modeler.html?modelId=' + this.modelId + '&t=' + `${new Date().getTime()}`
      console.log('生成的src---------', src)
      return src
    },
    apiUrl() {
      // "/server"; 后台部署的api服务
      return process.env.VUE_APP_BASE_API
    }
  },

  mounted() {
    // 全局存入当前vue实例，供activiti调用
    window.getMyVue = this
  },

  methods: {
    goto() {
      this.$message.success('保存模型成功')
      this.$router.push({ name: '/sys/activiti' })
    },

    handleClose(done) {
      this.$confirm('请记得点击左上角保存按钮，确定关闭设计窗口?', '确认关闭', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 关闭
        done()
        // 刷新数据
        this.$parent.fetchData()
      }).catch(() => {
      })
    }
  }
}
</script>
<style scoped>
.iframe {
  width: 100%;
  height: calc(100vh - 120px);
  border: 0px;
}
</style>
